package com.yhy.wxzn.wcs.enums;


import com.yhy.wxzn.wcs.device.rgv.bean.Lifter;
import com.yhy.wxzn.wcs.device.rgv.bean.Node;
import com.yhy.wxzn.wcs.entity.WcsDeviceInfo;
import com.yhy.wxzn.wcs.entity.WcsInboundDetail;
import com.yhy.wxzn.wcs.entity.WcsOutboundDetail;

import java.util.Arrays;

public enum LifterLocation {
    /**
     * 提升机左侧
     */
    LEFT(1, "左"),
    /**
     * 提升机内部
     */
    INSIDE(2, "中"),
    /**
     * 提升机右侧
     */
    RIGHT(3, "右")
    ;
    private int code;
    private String description;

     LifterLocation(int code, String description) {
        this.code = code;
        this.description = description;
    }





    /**
     * 返回对应层坐标的提升机相对位置
     * @param coords
     * @param deviceInfo
     * @param floor
     * @return
     */
    public static LifterLocation parseLifterLocation(String coords, WcsDeviceInfo deviceInfo, int floor) {
        Lifter lifter = Arrays.stream(coords.split(";"))
                .map(s -> Node.parseCoord(s))
                .filter(coord -> coord.getZ() == floor)
                .map(c -> new Lifter(c))
                .findFirst().get();

        Lifter inside = Lifter.parseLifter(deviceInfo.getLocation());


        if (lifter.equals(inside)) return INSIDE;

        if (lifter.getX() == inside.getX()){
            if (lifter.getY() > inside.getY())
                return RIGHT;
            else
                return LEFT;
        }else {
            if (lifter.getX() > inside.getX())
                return RIGHT;
            else
                return LEFT;
        }
    }

    public int getCode() {
        return this.code;
    }


    public String getDescription() {
        return description;
    }

    @Override
    public String toString() {
        return description;
    }


}
